#pragma once
#include "CMultiParentShareableDependencyObject.h"


class CBitmapImageReportCallback;
class ImageSurfaceWrapper;
class HWTextureManager;
class CTiledSurface;
class CRenderTarget;
class SurfaceCache;
class HWTexture;

class CImageSource :
	public CMultiParentShareableDependencyObject
{



protected: 
	CImageSource();
private: 
	CImageSource(CCoreServices *);
	void Initialize(CCoreServices * pCore);
protected: 
	virtual ~CImageSource();
	void SetDirty();
public: 
	static HRESULT Create(CDependencyObject * * ppObject, CREATEPARAMETERS * pCreate);
	virtual XUINT32 GetTypeIndex() const;
	virtual HRESULT AddCallback(CBitmapImageReportCallback * pImageErrorCallback);
	virtual void RemoveCallback(CBitmapImageReportCallback * pImageErrorCallback);
	virtual HRESULT ReloadImage();
	virtual HRESULT ReloadReleasedSoftwareImage();
	virtual HRESULT AddEventListener(CDependencyProperty * pdp, CValue * pValue, XINT32 iListenerType, CValue * pResult, XBOOL fHandledEventsToo);
	virtual HRESULT RemoveEventListener(CDependencyProperty * pdp, CValue * pValue);
	void SetKeepSystemMemory();
	virtual XUINT32 GetWidth();
	virtual XUINT32 GetHeight();
	virtual XUINT32 GetDisplayWidth();
	virtual XUINT32 GetDisplayHeight();
	virtual XBOOL IsOpaque();
	virtual XBOOL HasDimensions();
	XBOOL HasHardwareResources();
	void ResetSurfaces(XBOOL mustKeepSoftwareSurface);
	struct IPALSurface * GetSoftwareSurface();
	virtual HRESULT GetSoftwareSurfaceForPrinting(struct IPALSurface * * ppSoftwareSurface);
	void SetSoftwareSurface(struct IPALSurface * pSurface, XBOOL allowHardwareVideoSurface);
	CTiledSurface * GetTiledSurfaceNoRef();
	HRESULT OnPackageImageAvailable(struct IImageAvailableResponse *);
	virtual HRESULT HasProtectedContent(XBOOL * pfHasProtectedContent);
	virtual HRESULT GetCacheIdentifier(CXString * * ppCacheIdentifier);
	virtual HRESULT CancelDownload();
	virtual HRESULT EnsureAndUpdateHardwareResources(HWTextureManager * pTextureManager, CRenderTarget * pRenderTarget, SurfaceCache * pSurfaceCache);
	XBOOL HasLostHardwareResources();
	CXString * m_pstrSource;
	struct
	{
		XBOOL m_fSourceUpdated:1;
		XBOOL m_fSourceNeedsMeasure:1;
	};

protected: 
	HRESULT OnImageAvailableCommon(struct IImageAvailableResponse * pResponse);
	HRESULT CancelImageGet();
	virtual XUINT32 GetDecodeWidth();
	virtual XUINT32 GetDecodeHeight();
	virtual HRESULT ResetCallbackEvents();
	virtual HRESULT MarkHandledCallbackEvents();
	virtual HRESULT ResetForSourceChange(XBOOL mustKeepSoftwareSurfaces);
	struct IPALAbortableOperation * m_pImageGetOperation;
	ImageSurfaceWrapper * m_pImageSurfaceWrapper;
	XBOOL m_protectedContent;
	HWTexture * GetHardwareSurface();
	struct IPALAcceleratedBitmap * GetD2DBitmap();
	void SetD2DBitmap(struct IPALAcceleratedBitmap * pBitmap);
	HRESULT StartTiling(HWTextureManager *, XINT32, XINT32, XUINT32);
	virtual HRESULT HandleLostResources(SurfaceCache * pSurfaceCache, XBOOL * pWasDeviceLost);



};